package tman.main;

import common.configuration.Configuration;
import common.configuration.ExecutionConfiguration;
import common.simulation.scenarios.Scenario;
import common.simulation.scenarios.Scenario3;
import java.util.HashMap;

import tman.simulator.core.TManExecutionMain;
import tman.simulator.core.TManSimulationMain;
import common.configuration.Global;


public class BatchRunMain {
	public static void main(String[] args) throws Throwable {

  	    int seed = 4;  //Set seed for all RNGs used throughout the project
		
		setGlobals(args, seed); //Set necessary global variables
  	       
		//Configuration configuration = new Configuration();
		//configuration.set();
		
		ExecutionConfiguration executionConfiguration = new ExecutionConfiguration();
		executionConfiguration.set();
  	    
		Scenario3 scenario = new Scenario3();
		//scenario.setSeed(Global.seed);
		//scenario.setSeed(System.currentTimeMillis());
		
		//Uncomment to run simulation in single-threaded random mode
		scenario.getScenario().simulate(TManSimulationMain.class);
		
		//Uncomment to run simulation in a reproducible fashion
		//scenario.getScenario().sim(TManSimulationMain.class, args);
		
		//Uncomment to run simulation in real-time
		//scenario.getScenario().execute(TManExecutionMain.class);

	}
	
	private static void setGlobals(String[] args, int seed)
	{
		Global.odDistr = new HashMap<Integer, Integer>();
		String odDist = "";
  	    Global.seed = seed; //Set seed for all RNGs used throughout the project
		
		System.setProperty("id", args[0]);
  	    System.setProperty("sl", args[1]);
  	    System.setProperty("vs", args[2]);
  	    System.setProperty("tvs", args[3]); 	    
  	    System.setProperty("r", args[args.length-1]);
  	    System.setProperty("seed", String.valueOf(Global.seed));
  	    
  	    Global.id = Integer.parseInt(args[0]);
  	    Global.sl = Integer.parseInt(args[1]);
  	    Global.vs = Integer.parseInt(args[2]);
  	    Global.tvs = Integer.parseInt(args[3]);
  	    Global.r = Integer.parseInt(args[args.length-1]);
  	    
  	    for(int i=4; i<args.length-1; i++)
  	    {
  	    	if(i != 4)
  	    		odDist += ";";
  	    	String[] temp = args[i].split(":");
  	    	Global.odDistr.put(Integer.parseInt(temp[0]), Integer.parseInt(temp[1]));
  	    	odDist += temp[0] + ":" + temp[1];
  	    }
	    	System.out.println(odDist);
	    	System.setProperty("od", odDist);
	}
}
